package com.tabjin.rfidsocket.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * @author tabjin
 * create at 2020/12/8 11:39
 * @program rfid_socket
 * @description
 */
public class LevelUtil {
    public final static String SEPARATOR = ".";

    public final static String ROOT = "0";

    /**
     * 计算层级
     *
     * @param parentLevel 父级部门level
     * @param parentId    父级部门id
     * @return 层级字符串 如：
     * 0
     * 0.1
     * 0.1.2
     * 0.1.4
     * 0.4
     */
    public static String calculateLevel(String parentLevel, int parentId) {
        if (StringUtils.isBlank(parentLevel)) {// 空值即为首层
            return ROOT;
        } else {
            return StringUtils.join(parentLevel, SEPARATOR, parentId);
        }
    }
}
